package com.tianji.learning.controller;


import com.tianji.learning.domain.vo.PointsStatisticsVO;
import com.tianji.learning.service.IPointsRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 学习积分记录，每个月底清零 前端控制器
 * </p>
 *
 * @author xzh
 * @since 2024-03-18
 */
@RestController
@RequestMapping("/points")
@EnableScheduling
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
@Api(tags = "积分记录相关接口")
public class PointsRecordController {

    private final IPointsRecordService recordService;

    /**
     *每天24点清理redis中的pointsRecord记录 赋值为0
     */
    @Scheduled(cron ="0 0 0 * * ?")
    public void updateRedisPointsRecord(){
        recordService.updateRedisPointsRecord();
    }


    /**
     * 查询每天不同类型的积分情况
     * @return
     */
    @GetMapping("/today")
    @ApiOperation(value = "查询每天不同类型的积分情况")
    public List<PointsStatisticsVO> queryMyPointsToday(){
        return recordService.queryMyPointsToday();
    }
}
